package com.nbsystem.controller;

import com.nbsystem.entity.ElcNotice;
import com.nbsystem.entity.ElcUserInfotype;
import com.nbsystem.entity.SysUser;
import com.nbsystem.service.ElcNoticeService;
import com.nbsystem.service.ElcUserInfotypeService;
import com.nbsystem.util.Const;
import com.nbsystem.util.MyWorldFilter;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;


@Controller
public class IndexController {

    @Resource
    private ElcNoticeService elcNoticeService;

    @Resource
    private ElcUserInfotypeService elcUserInfotypeService;

    @RequestMapping("index")
    public String index(Model model) {
        model.addAttribute("msg", "");

        return "login";
    }


    @RequestMapping("user/index")
    public String userindex() {

        return "user/list";
    }

    @RequestMapping("notice/index")
    public ModelAndView noticeindex(HttpServletRequest request) {
        HttpSession session = request.getSession();
        SysUser sysUser = (SysUser) session.getAttribute(Const.USERSESSION);
        ModelAndView modelAndView = new ModelAndView();
        ElcUserInfotype elcUserInfotype = new ElcUserInfotype();
        elcUserInfotype.setUserId(sysUser.getId());
        modelAndView.addObject("infoTypeList",elcUserInfotypeService.queryAll(elcUserInfotype));
        modelAndView.setViewName("notice/list");
        return modelAndView;
    }

    @RequestMapping("role/index")
    public String roleindex() {

        return "role/list";
    }

    @RequestMapping("indexShow")
    public String indexShow() {

        return "indexShow";
    }

    @RequestMapping("comment/index")
    public String commentindex() {

        return "comment/list";
    }

    @RequestMapping("black/index")
    public String blackindex() {

        return "black/list";
    }



    @RequestMapping("showAddNotice")
    public String addNotice(){
        return "notice/addNotice";
    }

    @RequestMapping("showUpdateNotice/{id}")
    public String updateNotice(@PathVariable Integer id ,Model model){
        ElcNotice elcNotice = new ElcNotice();
        elcNotice = elcNoticeService.queryById(id);
        model.addAttribute(elcNotice);
        return "notice/updateNotice";
    }
    @RequestMapping("showNotice/{id}")
    public String showNotice(@PathVariable Integer id ,Model model){
        ElcNotice elcNotice = new ElcNotice();
        elcNotice = elcNoticeService.queryById(id);
        model.addAttribute(elcNotice);
        return "notice/showNotice";
    }

    @RequestMapping("column/index")
    public String column() {
        return "column/list";
    }


    @RequestMapping("main")
    public String main(){

        return "index";
    }
}
